class Test {
    private int num;

    Test() {
        num = 0;
    }

    Test(int num) {
        this.num = num;
    }

    int get() {
        return num;
    }

    void set(int num) {
        this.num = num;
    }

    public String toString() {
        return String.format("Test num = %d\n", num);
    }
}

// class Student implements Cloneable {
class Student {
    int age;
    Test o;

    Student() {
        age = 20;
        o = new Test();
    }

    Student(int age, int num) {
        this.age = age;
        this.o = new Test(num);
    }

    public String toString() {
        return String.format("age = %d, o = %d\n", age, o.get());
    }

    Student show() {
        System.out.printf("age = %d, o = %d\n", age, o.get());
        return this;
    }

    public boolean equals(Object obj) {
        if (obj instanceof Student) {
            Student stu = (Student)obj;
            if (this.age == stu.age && this.o.get() == stu.o.get())
                return true;
        }
        return false;
    }

    // public Object clone() throws CloneNotSupportedException {
    public Object clone() {
        return new Student(age, o.get()); //深拷贝
        // return super.clone();  //浅拷贝
    }
}

public class CloneTest {
    static public void main(String [] args) throws Exception {
        Student a = new Student(25, 199);
        Student b = (Student)a.clone();
        // Student b = a;
        // b.age = 45;
        // b.o.set(1000);
        // if (a == b) {
        if (a.equals(b)) {
            System.out.printf("两个对象是相等的!\n");
        }
        System.out.print(a);
        System.out.print(b);
    }
}
